<template>
  <div>
    <section class="section-2 relative">
      <p class="header">SUPPLIER LIST<span>申请列表</span></p>
      <div class="rules-item">
        <a-table  @change="handleTableChange" :pagination="pagination" :columns="columns" :data-source="list" :row-key="record => record.id">
          <template  slot="process_status" slot-scope="text, record">
            <span>{{record.process_status | getStatus}}</span>
          </template>
          <template  slot="operation" slot-scope="text, record">
            <a-button type="primary" @click="print(record)">打印</a-button>
            <a-button class="ml20" type="primary" @click="edit(record)">编辑</a-button>
            <a-button class="ml20" type="primary" @click="del(record)">删除</a-button>
          </template>
        </a-table>
      </div>
    </section>
  </div>
</template>
<script>
export default {
  name: 'association',
  data () {
    return {
      list: [],
      pagination: {
        total: 0,
        pageSize: 15,
        current: 1
      },
      pageNo: 1,
      pageSize: 15,
      columns: [{
        title: '序号',
        dataIndex: 'key',
        key: 'key',
        scopedSlots: { customRender: 'key' }
      }, {
        title: '成果名称',
        dataIndex: 'cgmch',
        key: 'cgmch',
        scopedSlots: { customRender: 'cgmch' }
      }, {
        title: '完成单位',
        dataIndex: 'wcdw',
        key: 'wcdw',
        scopedSlots: { customRender: 'wcdw' }
      }, {
        title: '联系人',
        dataIndex: 'lxren',
        key: 'lxren',
        scopedSlots: { customRender: 'lxren' }
      }, {
        title: '联系电话',
        dataIndex: 'lxdianhua',
        key: 'lxdianhua',
        scopedSlots: { customRender: 'lxdianhua' }
      }, {
        title: '申报单位',
        dataIndex: 'sqdw',
        key: 'sqdw',
        scopedSlots: { customRender: 'sqdw' }
      }, {
        title: '状态',
        dataIndex: 'process_status',
        key: 'process_status',
        scopedSlots: { customRender: 'process_status' }
      }, {
        title: '操作',
        dataIndex: 'operation',
        key: 'operation',
        scopedSlots: { customRender: 'operation' }
      }],
      keyword: '',
      form: this.$form.createForm(this)
    }
  },
  components: {
  },
  computed: {
  },
  created () {
    this.getArticles()
    this.validToken()
  },
  methods: {
    getArticles () {
      this.$http.queryCgjdFormList({
        pageNo: this.pagination.current,
        pageSize: this.pagination.pageSize
      }).then(res => {
        // res.data.list.forEach(v => {
        //   v.realPath = `${process.env.VUE_APP_SRC}${v.realPath}`
        // })
        res.data.list.map((v, i) => {
          v.key = i + 1
          return v
        })
        this.pagination.total = res.data.total
        this.list = res.data.list
      })
    },
    print (item) {
      if (item.process_status == 2) {
        this.$http.printCgjdForm({ id: item.id }).then(res => {
          if (res.data.fileUrl) {
            window.location.href = res.data.fileUrl
          }
        })
      } else {
        this.$message.warning("未审批通过，不能下载")
        return false
      }
    },
    edit (item) {
      if (item.process_status == 0 || item.process_status == 1) {
        this.$router.push({ path: `/innovation/supplier/1?id=${item.id}` })
      } else {
        this.$message.warning("待审批、待提交状态可修改")
        return false
      }
    },
    del (item) {
      this.$http.deleteCgjdForm({ id: item.id }).then(res => {
        this.getArticles()
      })
    },
    validToken () {
      this.$http.validToken({}).then(res => {
        if (!res.data) {
          this.$router.push({ path: '/login', query: { back: window.location.href } })
        }
      })
    },
    search () {
      this.pagination.current = 1
      this.getArticles()
    },
    handleTableChange (pagination) {
      this.pagination.current = pagination.current
      this.getArticles()
    },
    toDetail (item) {
      this.$router.push({ path: `/fold/${item.id}` })
    },
    down (url) {
      if (url) {
        window.location.href = url
      }
    }
  }
}
</script>
<style lang="scss">
</style>
